package com.anmingle.common;

import com.anmingle.enums.ErrorCode;

/**
 * @author 安明乐
 * @Title R  返回工具类
 * @Package IntelliJ IDEA
 * @date 2022/11/23 12:41
 */
public class R {

    /**
     * 成功
     * @param data
     * @param <T>
     * @return
     */
    public static <T> ResponseResult<T> ok(T data) {
        return new ResponseResult<>(0, "ok", data);
    }

    public static <T> ResponseResult<T> ok(String msg) {
        return new ResponseResult<>(0, msg);
    }


    public static <T> ResponseResult<T> ok(String msg, T data) {
        return new ResponseResult<>(0, msg, data);
    }

    /**
     * 失败
     * @param errorCode
     * @return
     */
    public static <T> ResponseResult<T> error(ErrorCode errorCode) {
        return new ResponseResult<>(errorCode);
    }

    /**
     * 失败自定义
     * @param code
     * @param msg
     * @return
     */
    public static <T> ResponseResult<T> error(int code, String msg) {
        return new ResponseResult<>(code, msg,null);
    }

    /**
     *  失败
     * @param errorCode
     * @param msg
     * @return
     */
    public static <T> ResponseResult<T> error(ErrorCode errorCode, String msg) {
        return new ResponseResult<>(errorCode.getCode(), msg,null);
    }



}
